package inherit;

/*class Base {
    int x;//Base中的x
    int y;
}

public class Derived extends Base{
    int x;//Derived中的x
    int z;

    public void method() {
        super.x = 100;//执行就近原则 - 子类优先
        y = 20;
        z = 30;
        System.out.println(x);
        System.out.println(y);
        System.out.println(z);
    }

    public static void main(String[] args) {
        Derived derived = new Derived();
        derived.method();
        Base base = new Derived();
        System.out.println("Base中的x：" + base.x);
    }
}*/

/*class Base {
    int x;//Base中的x
    int y;
}

public class Derived extends Base{
    int x;//Derived中的x
    int z;

    public void method() {
        super.x = 100;//访问父类
        y = 20;
        z = 30;
        System.out.println(x);
        System.out.println(super.x);
        System.out.println(y);
        System.out.println(z);
    }

    public static void main(String[] args) {
        Derived derived = new Derived();
        derived.method();

        //Base base = new Derived();
        //System.out.println("Base中的x：" + base.x);
    }
}*/

class Base {
    int x;//Base中的x
    int y;
    public void methodA() {
        System.out.println("Base中的methodA方法");
    }
}

public class Derived extends Base {
    int x;//Derived中的x
    int z;
    public void methodA() {
        System.out.println("Derived中的methodA方法");
    }
    public void methodB() {
        System.out.println("Derived中的methodB方法");
    }

    public void methodC() {
        methodB();//访问子类自己的methodB()
        methodA();//访问父类继承的methodA()
        //methoD()//;//编译失败，在整个继承体系中没有发现方法Derived()
    }
}

